//
//  YHYShowActivityViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/6/29.
//  Copyright © 2016年 LanJue. All rights reserved.
//

//#import <AssetsLibrary/AssetsLibrary.h>

#import "YHYShowActivityViewController.h"
#import "YHYDesignerPTableViewCell.h"
#import "YHYAcitvityButtonTableViewCell.h"
#import "TZImagePickerController.h"

#import "YHYActivityPictureTableViewCell.h"
@interface YHYShowActivityViewController ()<UITableViewDataSource,UITableViewDelegate,YHYActivitydelegate,TZImagePickerControllerDelegate>
@property (nonatomic,strong)  UITableView *myTableView;
@property (nonatomic, strong) NSArray *array;

@property (nonatomic,strong) NSMutableDictionary *bigDic;
@property (nonatomic,strong) NSMutableArray *bigArray;
@property (nonatomic,assign) NSInteger munTime;


@property(nonatomic,retain)UIButton *placeImageButton;
@property(nonatomic,retain)NSMutableArray *imageArray;

@end

@implementation YHYShowActivityViewController



-(void) viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
    self.tabBarController.tabBar.hidden=YES;
    
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
    self.tabBarController.tabBar.hidden=NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发布活动";
    [self creatView];
//    _selectedPhotos = [NSMutableArray array];
    self.array = [NSArray arrayWithObjects:@"活动标题", @"活动时间", @"活动地点", nil];
    _munTime = 1;
    _bigDic = [NSMutableDictionary dictionary];
    // Do any additional setup after loading the view.
}


- (void)creatView{
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    _bigArray = [NSMutableArray array];
    _bigDic = [NSMutableDictionary dictionary];
    _myTableView = [UITableView new];
    [self.view addSubview:_myTableView];
    [_myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.mas_equalTo(self.view);
        make.width.mas_equalTo(self.view);
        make.height.mas_equalTo(self.view);
        
    }];
    
    _myTableView.backgroundColor = LV;
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    [_myTableView registerClass:[YHYDesignerPTableViewCell class] forCellReuseIdentifier:@"YHYDesignerPTableViewCell"];
    [_myTableView registerClass:[YHYAcitvityButtonTableViewCell class] forCellReuseIdentifier:@"YHYAcitvityButtonTableViewCell"];
    [_myTableView registerClass:[YHYDesignerPTableViewCell class] forCellReuseIdentifier:@"cell4"];
    [_myTableView registerClass:[YHYActivityPictureTableViewCell class] forCellReuseIdentifier:@"YHYActivityPictureTableViewCell"];
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 180)];
    _myTableView.tableFooterView = footView;
    footView.backgroundColor = [UIColor redColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(footAction:)];
    [footView addGestureRecognizer:tap];
    [_myTableView reloadData];
   }
-(void)Back:(UIBarButtonItem *)back{


    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)footAction:(UITapGestureRecognizer *)tap{
     [self pickPhotoButtonClick:nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
     YHYDesignerPTableViewCell *cell4 = [tableView dequeueReusableCellWithIdentifier:@"YHYDesignerPTableViewCell"];
    
    if (indexPath.section == 0) {
        cell4.xmLabel.text = [_array objectAtIndex:indexPath.row];
   
        if (indexPath.row == 1) {
             cell4.num = 1;
            
        }
        
    }
   else if (indexPath.section == 1) {
        YHYDesignerPTableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell4"];
        cell1.xmLabel.text = @"发布范围";
        return cell1;
    }
   else if (indexPath.section == 2) {
        YHYAcitvityButtonTableViewCell *cellFaBu = [tableView dequeueReusableCellWithIdentifier:@"YHYAcitvityButtonTableViewCell"];
        if (indexPath.row == 0 ) {
            cellFaBu.xmLabel.text = @"推荐人群";
            
        }
        return cellFaBu;
    }
    
    
    if (indexPath.section >= 3) {
 
    YHYActivityPictureTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:@"YHYActivityPictureTableViewCell"];
    
        
    cell3.myImageView.image = [UIImage imageNamed:@"1"];
        cell3.backgroundColor = [UIColor blueColor];
        return cell3;
    }
     return cell4;
}

   
    



- (IBAction)pickPhotoButtonClick:(UIButton *)sender {
    NSInteger mum = 9;
    
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc]initWithMaxImagesCount:mum selectArr:_selectedPhotos delegate:self];
    imagePickerVc.selectCount = _selectedPhotos.count;
    [self presentViewController:imagePickerVc animated:YES completion:nil];
    [_myTableView reloadData];
    
}



-(void)buttonAction:(UIButton *)button{
    
//    [_myTableView reloadData];
    

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 3) {
         [self pickPhotoButtonClick:nil];
            }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_bigDic.allKeys.count >= 1) {
        if (indexPath.section == 0) {
            return  ROWHEIGHT;
            
        }
        if (indexPath.section == 1) {
            return ROWHEIGHT;
        }
        if (indexPath.section == 2) {
            return 80 * AUTO_HEIGHT;
        }
        //
        NSMutableArray *array = [NSMutableArray array];
        
        
        for (int i = 0; i < _bigDic.allKeys.count;) {
            i++;
            if (indexPath.section == 2 + i) {
                array = [_bigDic objectForKey:[NSString stringWithFormat:@"%d", i]];
                return array.count * ROWHEIGHT;
            }
            
        }
        
    }
    else{
        if (indexPath.section == 0) {
            return ROWHEIGHT;
            
        }
        if (indexPath.section == 1) {
            return ROWHEIGHT;
        }
        if (indexPath.section == 2) {
            return 80 * AUTO_HEIGHT;
        }
        
        return ROWHEIGHT;
    }
    
    return ROWHEIGHT;
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_bigDic.allKeys.count >= 1) {
        if (section == 0) {
            return _array.count;
            
        }
        if (section == 1) {
            return 1;
        }
        if (section == 2) {
            return 1;
        }
//
        NSMutableArray *array = [NSMutableArray array];
        
       
        for (int i = 0; i < _bigDic.allKeys.count;) {
            i++;
            if (section == 2 + i) {
           array = [_bigDic objectForKey:[NSString stringWithFormat:@"%d", i]];
                return array.count;
            }
            
        }

    }
    else{
        if (section == 0) {
            return _array.count;
            
        }
        if (section == 1) {
            return 1;
        }
        if (section == 2) {
            return 1;
        }

        return 1;
           }
    
    return 1;
    
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3  + _bigDic.allKeys.count;//区
}

//- (IBAction)pickPhotoButtonClick:(UIButton *)sender {
//    NSInteger mum = 9;
//    
//    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc]initWithMaxImagesCount:mum selectArr:_selectedPhotos delegate:self];
//    imagePickerVc.selectCount = _selectedPhotos.count;
//    [self presentViewController:imagePickerVc animated:YES completion:nil];
//    [_myTableView reloadData];
//    
//}
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets{
    _selectedPhotos = [NSMutableArray arrayWithArray:photos];
    NSLog(@"jjj=%@",_selectedPhotos);
    [_bigDic setObject:_selectedPhotos forKey:[NSString stringWithFormat:@"%ld",_munTime]];
    _munTime ++;
    [_myTableView reloadData];

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0;
    }
    else{
        return 10 * AUTO_HEIGHT;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


//
//  YHYShowActivityViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/6/29.
//  Copyright © 2016年 LanJue. All rights reserved.
//
//
//#import <AssetsLibrary/AssetsLibrary.h>
//
//#import "YHYShowActivityViewController.h"
//#import "YHYDesignerPTableViewCell.h"
//#import "YHYAcitvityButtonTableViewCell.h"
//#import "TZImagePickerController.h"
//
//#import "YHYActivityPictureTableViewCell.h"
//@interface YHYShowActivityViewController ()<UITableViewDataSource,UITableViewDelegate,YHYActivitydelegate>
//@property (nonatomic,strong)  UITableView *myTableView;
//@property (nonatomic, strong) NSArray *array;
//
//@property (nonatomic,strong) NSMutableDictionary *bigDic;
//@property (nonatomic,strong) NSMutableArray *bigArray;
//@property (nonatomic,assign) NSInteger munTime;
//@end
//
//@implementation YHYShowActivityViewController
//
//
//
//-(void) viewWillAppear:(BOOL)animated
//{
//    self.navigationController.navigationBarHidden=NO;
//    self.tabBarController.tabBar.hidden=YES;
//    
//}
//
//-(void) viewWillDisappear:(BOOL)animated
//{
//    self.navigationController.navigationBarHidden=NO;
//    self.tabBarController.tabBar.hidden=NO;
//}
//
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    self.title = @"发布活动";
//    [self creatView];
//    _selectedPhotos = [NSMutableArray array];
//    self.array = [NSArray arrayWithObjects:@"活动标题", @"活动时间", @"活动地点", nil];
//    _munTime = 0;
//    _bigDic = [NSMutableDictionary dictionary];
//    // Do any additional setup after loading the view.
//}
//
//
//- (void)creatView{
//    
//    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
//    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
//    _bigArray = [NSMutableArray array];
//    _bigDic = [NSMutableDictionary dictionary];
//    _myTableView = [UITableView new];
//    [self.view addSubview:_myTableView];
//    [_myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.view);
//        make.left.mas_equalTo(self.view);
//        make.width.mas_equalTo(self.view);
//        make.height.mas_equalTo(self.view);
//        
//    }];
//    
//    _myTableView.backgroundColor = LV;
//    _myTableView.delegate = self;
//    _myTableView.dataSource = self;
//    [_myTableView registerClass:[YHYDesignerPTableViewCell class] forCellReuseIdentifier:@"YHYDesignerPTableViewCell"];
//    [_myTableView registerClass:[YHYAcitvityButtonTableViewCell class] forCellReuseIdentifier:@"YHYAcitvityButtonTableViewCell"];
//    [_myTableView registerClass:[YHYActivityPictureTableViewCell class] forCellReuseIdentifier:@"YHYActivityPictureTableViewCell"];
//    [_myTableView reloadData];
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    
//    
//    YHYDesignerPTableViewCell *cell4 = [tableView dequeueReusableCellWithIdentifier:@"YHYDesignerPTableViewCell"];
//    if (indexPath.section == 0) {
//        
//        cell4.xmLabel.text = [_array objectAtIndex:indexPath.row];
//        
//        if (indexPath.row == 1) {
//            cell4.num = 1;
//            
//        }
//        
//    } else if (indexPath.section == 1) {
//        YHYDesignerPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYDesignerPTableViewCell"];
//        cell.xmLabel.text = @"发布范围";
//    } else if (indexPath.section == 2) {
//        YHYAcitvityButtonTableViewCell *cellFaBu = [tableView dequeueReusableCellWithIdentifier:@"YHYAcitvityButtonTableViewCell"];
//        if (indexPath.row == 0 ) {
//            cellFaBu.xmLabel.text = @"推荐人群";
//            
//        }
//        return cellFaBu;
//    } else  {
//        YHYActivityPictureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYActivityPictureTableViewCell"];
//        
//        NSMutableArray *ar = [NSMutableArray new];
//        
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.delegate = self;
//        if (_bigDic.allKeys.count != 0) {
//            for (int i = 0; i < _bigDic.allKeys.count; i++) {
//                if (indexPath.section == 2 + _bigDic.allKeys.count) {
//                    ar = [_bigDic objectForKey:_bigDic.allKeys[i]];
//                    
//                }
//                cell.myImageView.image = ar[indexPath.row];
//            }
//            
//        }else{
//            cell.myImageView.image =[UIImage imageNamed:@"1"];
//        }
//        
//        
//        
//        //                if (_selectedPhotos.count != 0) {
//        ////            NSArray *array = [_selectedPhotos objectAtIndex:0];
//        //            cell2.myImageView.image = [_selectedPhotos objectAtIndex:indexPath.row];
//        //        }
//        //        else{
//        //            cell2.myImageView.image =[UIImage imageNamed:@"1"];
//        //        }
//        //        cell2.myImageView.contentMode = UIViewContentModeRedraw;
//        //        [self generatePhotoThumbnail:[_selectedPhotos objectAtIndex:indexPath.row]];
//        return cell;
//    }
//    
//    
//    return cell4;
//}
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 3) {
//        [self pickPhotoButtonClick:nil];
//    }
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    
//    //    if (_bigDic.allKeys.count != 0) {
//    //
//    //    else{
//    //        for (int i = 0; i < _bigDic.allKeys.count; i++) {
//    //            if (indexPath.section == 3 + _bigDic.allKeys.count) {
//    //
//    //             ar = [_bigDic objectForKey:_bigDic.allKeys[i]];
//    //            }
//    //        }
//    //        return ar.count * 100 * AUTO_HEIGHT;
//    //
//    //    }
//    //
//    //    }
//    //
//    
//    
//    
//    if (_bigDic.allKeys.count != 0) {
//        NSMutableArray *ar =  _selectedPhotos;
//        
//        if (indexPath.section == 1 || indexPath.section == 0) {
//            return ROWHEIGHT;
//            
//        }
//        if (indexPath.section == 2) {
//            return 80 * AUTO_HEIGHT;
//        }
//        //        for (int i = 0; i < _bigDic.allKeys.count; i++) {
//        //            if (indexPath.section == 2 + _bigDic.allKeys.count) {
//        //                ar = [_bigDic objectForKey:_bigDic.allKeys[i]];
//        //            }
//        //        }
//        if (indexPath.section == _bigDic.allKeys.count + 2) {
//            
//            if (ar == nil) {
//                return 0;
//            } else {
//                return ar.count * 100 * AUTO_HEIGHT;
//            }
//            
//            
//        }
//    }
//    else{
//        if (indexPath.section == 2) {
//            return 80 * AUTO_HEIGHT;
//        }
//        else{
//            return ROWHEIGHT;
//        }
//    }
//    return ROWHEIGHT;
//}
//
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    if (section == 0) {
//        return 0;
//    }
//    else{
//        return 10 * AUTO_HEIGHT;
//    }
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if (section == 0) {
//        return _array.count;
//    }
//    if (section == 1) {
//        return 1;
//    }
//    if (section == 2) {
//        return 1;
//    }
//    if (section == 3) {
//        
//        if (_bigDic.allKeys.count != 0) {
//            return 1;
//        }
//        else{
//            
//            return _selectedPhotos.count;
//        }
//    }
//    else{
//        return 1;
//    }
//}
//
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    return 5 + _bigDic.allKeys.count;//区
//}
//
//- (IBAction)pickPhotoButtonClick:(UIButton *)sender {
//    NSInteger mum = 9;
//    
//    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc]initWithMaxImagesCount:mum selectArr:_selectedPhotos delegate:self];
//    imagePickerVc.selectCount = _selectedPhotos.count;
//    [self presentViewController:imagePickerVc animated:YES completion:nil];
//    [_myTableView reloadData];
//    
//}
//- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets{
//    _munTime ++;
//    
//    _selectedPhotos = [NSMutableArray arrayWithArray:photos];
//    
//    [_bigDic setObject:_selectedPhotos forKey:[NSString stringWithFormat:@"%ld",_munTime]];
//    NSLog(@"%ld",_bigDic.allKeys.count);
//    [_myTableView reloadData];
//    
//}
//
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
//
///*
// #pragma mark - Navigation
// 
// // In a storyboard-based application, you will often want to do a little preparation before navigation
// - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// // Get the new view controller using [segue destinationViewController].
// // Pass the selected object to the new view controller.
// }
// */
//
//@end
